package pl.softech.gpw.candles.patterns.impl2;

import pl.softech.gpw.candles.Candle;

public class CandleSeqEngfulsBodyRule implements IRule {

    private boolean match(int index1, int index2, Candle[] pattern, Candle[] candles) {
        
        if(pattern[index1].engulfsBody(pattern[index2]) != candles[index1].engulfsBody(candles[index2])) {
            return false;
        }
        
        return true;
        
    }
    
    @Override
    public boolean match(Candle[] pattern, Candle[] candles) {
        
        for(int i = 0; i < pattern.length - 1; i++) {
            
            if(!match(i, i + 1, pattern, candles)) {
                return false;
            }
            
            if(!match(i + 1, i, pattern, candles)) {
                return false;
            }
            
        }
        
        return true;
    }

}
